from django.db import models
from reportservice.helpers import TableModel
import uuid
# Create your models here.
class HzfwQrCode(TableModel):
    report_code = models.CharField(max_length=64)
    company_name = models.CharField(max_length=64)
    qr_code_content = models.CharField(max_length=256)
    org_id = models.CharField(max_length=64)
    pdf_path = models.CharField(max_length=256,null=True,blank=True)
    is_uploaded = models.BooleanField(default=False)

    class Meta:
        db_table = 'xm_hzfw_qr_code'
    def __str__(self) -> str:
        return super().__str__()
    

class DocxRenderRecord(TableModel):
    task_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
    render_data = models.JSONField(default=dict)
    company_name = models.CharField(max_length=64)
    origin_pdf_path = models.CharField(max_length=256,null=True,blank=True)
    signed_pdf_path = models.CharField(max_length=256,null=True,blank=True)
    model_id = models.IntegerField()

    class Meta:
        db_table = 'xm_docx_render_record'
    def __str__(self) -> str:
        return super().__str__()
    


class JgData(models.Model):
    #主键
    id = models.AutoField(primary_key=True)
    # 报告的表单实例ID
    report_form_inst_id = models.CharField(max_length=64, null=True,blank=True,verbose_name="报告的表单实例ID")
    # 合同的form_inst_id
    contract_form_inst_id = models.CharField(max_length=64, null=True,blank=True,verbose_name="合同表单实例ID")
    # 合同编号
    contract_number = models.CharField(max_length=64, null=True, blank=True, verbose_name="合同编号")
    # 报告发放日期
    report_issue_date = models.DateField(null=True, blank=True, verbose_name="报告发放日期")
    # 委托编号
    commission_number = models.CharField(max_length=128, null=True, blank=True, verbose_name="委托编号")
    # 原始记录编号
    original_record_number = models.CharField(max_length=64, null=True, blank=True, verbose_name="原始记录编号")
    # 报告编号
    report_number = models.CharField(max_length=64, null=True, blank=True, verbose_name="报告编号")
    # 工程名称
    project_name = models.CharField(max_length=128, null=True, blank=True, verbose_name="工程名称")
    # 工程名称（报告）
    project_name_report = models.CharField(max_length=128, null=True, blank=True, verbose_name="工程名称（报告）")
    # 工程地址
    project_address = models.CharField(max_length=128, null=True, blank=True, verbose_name="工程地址")
    # 建筑面积
    building_area = models.CharField(max_length=64,null=True, blank=True, verbose_name="建筑面积")
    # 签订日期
    contract_date = models.DateField(null=True, blank=True, verbose_name="签订日期")
    # 甲方名称
    party_a_name = models.CharField(max_length=128, null=True, blank=True, verbose_name="甲方名称")
    # 业务类型
    business_type = models.CharField(max_length=64, null=True, blank=True, verbose_name="业务类型")
    # 鉴定报告日期
    appraisal_report_date = models.DateField(null=True, blank=True, verbose_name="鉴定报告日期")
    # 鉴定等级
    appraisal_grade = models.CharField(max_length=64, null=True, blank=True, verbose_name="鉴定等级")
    # 合同单价
    unit_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name="合同单价")
    # 合同金额
    contract_amount = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True, verbose_name="合同金额")
    # 存档盒号
    archive_box_number = models.CharField(max_length=64, null=True, blank=True, verbose_name="存档盒号")
    # 原始记录附件_文件名称
    original_record_attachment = models.CharField(max_length=128, null=True, blank=True, verbose_name="原始记录附件")
    # 合同邮寄日期
    contract_mail_date = models.DateField(null=True, blank=True, verbose_name="合同邮寄日期")
    # 合同收回日期
    contract_retrieval_date = models.DateField(null=True, blank=True, verbose_name="合同收回日期")
    # 开票单位
    billing_unit = models.CharField(max_length=128, null=True, blank=True, verbose_name="开票单位")
    # 开票日期
    billing_date = models.DateField(null=True, blank=True, verbose_name="开票日期")
    # 开票金额
    billing_amount = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name="开票金额")
    # 检测人
    inspector = models.CharField(max_length=64, null=True, blank=True, verbose_name="检测人")
    # 项目负责人
    project_leader = models.CharField(max_length=64, null=True, blank=True, verbose_name="项目负责人")
    # 项目地区
    project_area = models.CharField(max_length=128, null=True, blank=True, verbose_name="项目地区")
    # 合同业务员
    contract_salesman = models.CharField(max_length=64, null=True, blank=True, verbose_name="合同业务员")
    # 创建时间
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    class Meta:
        db_table = 'jg_records'
        verbose_name = "结构总表数据记录"

    def __str__(self):
        return f"{self.project_name} - {self.report_number}"